package com.wxdc.nmgyt.nmgytwydc.presenter;

import com.wxdc.nmgyt.nmgytwydc.base.RxPersenter;
import com.wxdc.nmgyt.nmgytwydc.http.RetrofitHelper;
import com.wxdc.nmgyt.nmgytwydc.presenter.contract.NavigationHomeContract;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/8/13.
 */

public class NavigationHomePersenter extends RxPersenter<NavigationHomeContract.View> implements NavigationHomeContract.Persenter {
    private RetrofitHelper mRetrofitHelper;
    @Inject
    public NavigationHomePersenter(RetrofitHelper retrofitHelper) {
        mRetrofitHelper = retrofitHelper;
    }

    /**
     * 请求服务器，获取最新公告内容
     */
    @Override
    public void getNoticeContent() {
        mRetrofitHelper.getNoticeContentFun()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        addDisposable(d);
                    }

                    @Override
                    public void onNext(String s) {
                        mView.showNoticeContent(s);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.showError("公告内容请求失败");
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
